package com.sinoglobal.ningxia.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.sinoglobal.dumping.util.PicassoCircleImageTransFormat;
import com.sinoglobal.ningxia.R;
import com.sinoglobal.ningxia.beans.CommentBean;
import com.squareup.picasso.Picasso;

import net.tsz.afinal.FinalBitmap;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by XINDZ on 2017/2/15.
 * 功能:
 */

public class VideoPlayerCommentAdapter extends BaseAdapter {
    private LayoutInflater mInflater;
    List<CommentBean.ListBean> commentList = new ArrayList();
    Context context;
    FinalBitmap fb;

    public VideoPlayerCommentAdapter(Context context) {
        this.context = context;
        mInflater = LayoutInflater.from(context);
        fb = FinalBitmap.create(context);
    }

    public VideoPlayerCommentAdapter(Context context, List<CommentBean.ListBean> commentList) {
        this.commentList = commentList;
        this.context = context;
        mInflater = LayoutInflater.from(context);
        fb = FinalBitmap.create(context);
    }

    @Override
    public int getCount() {
        return commentList.size();
    }

    @Override
    public Object getItem(int i) {
        return commentList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    public void setCommentList(List commentList) {
        this.commentList = commentList;
        notifyDataSetChanged();
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Holder holder;
        if (view == null) {
            holder = new Holder();
            view = mInflater.inflate(R.layout.item_videoplay_comment, null);
            holder.iv_faming_detail_imag = (ImageView) view.findViewById(R.id.iv_faming_detail_imag);
            holder.tv_detail_username = (TextView) view.findViewById(R.id.tv_detail_username);
            holder.tv_faming_detail_time = (TextView) view.findViewById(R.id.tv_faming_detail_time);
            holder.tv_faming_detail_content = (TextView) view.findViewById(R.id.tv_faming_detail_content);
            view.setTag(holder);
        } else {
            holder = (Holder) view.getTag();
        }
        CommentBean.ListBean listBean = commentList.get(i);
        String content = listBean.getContent();
        String time = listBean.getCreate_time();
        String nickname = listBean.getNickname();
        String user_img = listBean.getUser_img();
        if (user_img != null && !user_img.equals("")) {
            Picasso.with(context).load(user_img).transform(new PicassoCircleImageTransFormat())
                    .placeholder(R.drawable.personal_list_portrait).error(R.drawable.personal_list_portrait)
                    .into(holder.iv_faming_detail_imag);
        } else {
            Picasso.with(context).load(R.drawable.personal_list_portrait).transform(new PicassoCircleImageTransFormat())
                    .into(holder.iv_faming_detail_imag);
        }

        holder.tv_faming_detail_content.setText(content);
        holder.tv_detail_username.setText(nickname);
        holder.tv_faming_detail_time.setText(time);
        return view;
    }


    static class Holder {
        public ImageView iv_faming_detail_imag;
        public TextView tv_detail_username;
        public TextView tv_faming_detail_time;
        public TextView tv_faming_detail_content;
    }
}

